// var baseUrl =
//   process.env.NODE_ENV == "development"
//     ? "http://192.168.0.12:12015/wycms-api"
//     : "/wycms-api";
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (elt) {
    var len = this.length >>> 0;
    var from = Number(arguments[1]) || 0;
    from = from < 0 ? Math.ceil(from) : Math.floor(from);
    if (from < 0) from += len;
    for (; from < len; from++) {
      if (from in this && this[from] === elt) return from;
    }
    return -1;
  };
}
var baseUrl = "/wycms-api";
var firstEnergyStateDetail = {};

function handleResponse(res) {
  firstEnergyStateDetail = res.data;
  var s = "";
  s += `<marquee scrollamount="1" direction="up" width="100%" height="70" onMouseOver="this.stop();"
      onMouseOut="this.start();">
      <span>
        <p class="title">电网运行情况</p>`;

  s += `<p class="item">
          <span class="left">今日日期：</span>
          <span class="right">${firstEnergyStateDetail.times}</span>
        </p>`;

  s += `
        <p class="item">
          <span class="left">${
            ["yc", "jc"].indexOf(city_name) > -1
              ? "网供指标"
              : ["ll"].indexOf(city_name) > -1
              ? "网供最大负荷"
              : ""
          }</span>
          <span class="right">${firstEnergyStateDetail.netTarget}万千瓦</span>
        </p>
        `;

  s += `
         <p class="item">
          <span class="left">${
            ["yc", "jc"].indexOf(city_name) > -1
              ? "网供电量"
              : ["ll"].indexOf(city_name) > -1
              ? "供电量"
              : ""
          }</span>
          <span class="right">${firstEnergyStateDetail.netEnergy}万千瓦时</span>
        </p>
        `;

  s += `<p class="item">
          <span class="left">${
            ["yc", "jc"].indexOf(city_name) > -1
              ? "最大网供负荷"
              : ["ll"].indexOf(city_name) > -1
              ? "网供最小负荷"
              : ""
          }</span>
          <span class="right">${firstEnergyStateDetail.maxNetLoad}万千瓦</span>
        </p>`;

  if (["yc", "jc"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">整点最大负荷</span>
          <span class="right">${firstEnergyStateDetail.maxPointLoad}万千瓦</span>
        </p>`;
  }

  if (["yc", "jc"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">整点最小负荷</span>
          <span class="right">${firstEnergyStateDetail.minPointLoad}万千瓦</span>
        </p>`;
  }
  if (["yc", "jc"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">限电最大负荷</span>
          <span class="right">${firstEnergyStateDetail.limitMaxLoad}万千瓦</span>
        </p>`;
  }

  if (["yc", "jc"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">拉路条次</span>
          <span class="right">${firstEnergyStateDetail.cutNum}万千瓦</span>
        </p>`;
  }
  if (["yc", "jc"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">限电损失</span>
          <span class="right">${firstEnergyStateDetail.cutLosing}万千瓦</span>
        </p>`;
  }

  if (["jc"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">全区最大负荷</span>
          <span class="right">${firstEnergyStateDetail.zdfh}万千瓦</span>
        </p>`;
  }

  if (["ll"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">发电量</span>
          <span class="right">${firstEnergyStateDetail.netFaDian}万千瓦</span>
        </p>`;
  }
  if (["ll"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">峰谷率</span>
          <span class="right">${firstEnergyStateDetail.netFengGu}万千瓦</span>
        </p>`;
  }

  if (["ll"].indexOf(city_name) > -1) {
    s += `<p class="item">
          <span class="left">负荷率</span>
          <span class="right">${firstEnergyStateDetail.netLoadRate}万千瓦</span>
        </p>`;
  }

  s += `</span></marquee>`;

  $(".firstEnergyState").append(s);
}
function getEnergyStateDetail() {
  var query = getQuery();
  $.ajax({
    url: baseUrl + "/customize/energyState/index",
    method: "post",
    data: { siteId: query.siteId },
    success: handleResponse,
  });
}

getEnergyStateDetail();
